package com.cotte.flow.util;

import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cotte.flow.model.DgraphRelations;
import com.cotte.flow.model.DgraphSteps;
import com.google.gson.Gson;

import io.dgraph.DgraphClient;
import io.dgraph.DgraphProto.Response;

public class Transform {
	
	private static Gson gson = new Gson();
	/**
	 * 
	 * <p>Title: jsonTransform</p>  
	 * <p>Description: </p>  
	 * @param response
	 * @param name
	 * @return
	 */
	public static String jsonTransform(Response response,String name) {
		String json = response.getJson().toStringUtf8();
		Map<String,JSONArray> maps = (Map<String,JSONArray>)JSON.parse(json); 
		 JSONArray array = maps.get(name);
		 String strJson = null;
		 if(array.size() > 0) {
			 JSONObject obj = array.getJSONObject(0); 
			 strJson = gson.toJson(obj);
		 }
		 return strJson;
	}
	
	
}
